package com.hengda.smart.speak.d.config;

import android.database.Cursor;

import com.hengda.smart.speak.d.bean.ExhibitInfo;
import com.hengda.smart.speak.d.bean.UnitInfo;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @Description 将数据库字段解析成数组
 * @author wzq
 * @date 2015-7-15 下午6:58:19
 * @update (date)
 * @version V1.0
 */
public class DataBaseUtil {

	/** 资源自动编号 **/
	private final static String FIELD_AUTONUM = "AutoNum";
	/** 资源名称编号 **/
	private final static String FIELD_FILENO = "FileNo";
	/** 资源名称 **/
	private final static String FIELD_NAME = "FileName";
	/** 资源路径**/
	private final static String FIELD_PATH = "FilePath";
	/** 列表**/
	private final static String FIELD_UNITTYPE = "UnitType";
	/** 列表**/
	private final static String FIELD_FILETYPE= "FileType";
	/** 展厅信息**/
	private final static String FIELD_UNITNO = "UnitNo";
	private final static String FIELD_UNIT_MAIN_NAME = "UnitMainName";
	private final static String FIELD_UNIT_EXTEND_NAME = "UnitExtendName";

	/**
	 *
	 * @Description: 获取数据库list集合
	 * @param c
	 * @return
	 * @return List<ExhibitInfo>
	 * @throws
	 * @autour wzq
	 * @date 2015-7-15 下午7:38:39
	 * @update (date)
	 */

	public static List<ExhibitInfo> getRsInfoList(Cursor c) {
		List<ExhibitInfo> infoList = new ArrayList<ExhibitInfo>();
		if (c != null) {
			while (c.moveToNext()) {
				ExhibitInfo exhibitInfo = new ExhibitInfo();
				exhibitInfo.setAutoNo(c.getInt(c.getColumnIndex(FIELD_AUTONUM)));
				exhibitInfo.setFileNo(c.getString(c.getColumnIndex(FIELD_FILENO)));
				exhibitInfo.setFileName(c.getString(c.getColumnIndex(FIELD_NAME)));
				exhibitInfo.setFilePath(c.getString(c.getColumnIndex(FIELD_PATH)));
				exhibitInfo.setUnitType(c.getInt(c.getColumnIndex(FIELD_UNITTYPE)));
				exhibitInfo.setType(c.getString(c.getColumnIndex(FIELD_FILETYPE)));
				infoList.add(exhibitInfo);
			}
			return infoList;
		} else {
			return null;
		}
	}

	/**
	 *
	 * @Description: 获取数据库list集合
	 * @param c
	 * @return
	 * @return List<AreaInfo>
	 * @throws
	 * @autour wzq
	 * @date 2015-7-15 下午7:38:39
	 * @update (date)
	 */
	public static ExhibitInfo getAreaInfo(Cursor c) {
		ExhibitInfo areaInfo = new ExhibitInfo();
		if (c != null) {
			c.moveToNext();
			areaInfo.setAutoNo(c.getInt(c.getColumnIndex(FIELD_AUTONUM)));
			areaInfo.setFileNo(c.getString(c.getColumnIndex(FIELD_FILENO)));
			areaInfo.setFileName(c.getString(c.getColumnIndex(FIELD_NAME)));
			areaInfo.setFilePath(c.getString(c.getColumnIndex(FIELD_PATH)));
			areaInfo.setUnitType(c.getInt(c.getColumnIndex(FIELD_UNITTYPE)));
			areaInfo.setType(c.getString(c.getColumnIndex(FIELD_FILETYPE)));
			return areaInfo;
		} else {
			return null;
		}
	}

	/**
	 *
	 * @Description: 获取单元集合
	 * @param c
	 * @return
	 * @return List<UnitInfo>
	 * @throws
	 * @autour WZQ
	 * @date 2016-6-14 下午7:42:01
	 * @update (date)
	 */
	public static List<UnitInfo> getUnitList(Cursor c){
		List<UnitInfo> unitList = new ArrayList<UnitInfo>();
		if (c != null) {
			while (c.moveToNext()) {
				UnitInfo exhibitInfo = new UnitInfo();
				exhibitInfo.setUnitNo(c.getInt(c.getColumnIndex(FIELD_UNITNO)));
				exhibitInfo.setUnitNameMain(c.getString(c.getColumnIndex(FIELD_UNIT_MAIN_NAME)));
				exhibitInfo.setUnitNameSmall(c.getString(c.getColumnIndex(FIELD_UNIT_EXTEND_NAME)));
				exhibitInfo.setUnitType(c.getInt(c.getColumnIndex(FIELD_UNITTYPE)));
				unitList.add(exhibitInfo);
			}
			return unitList;
		} else {
			return null;
		}
	}



}
